package com.lzb.browser;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;

import androidx.appcompat.app.AppCompatActivity;

import com.lzb.browser.activity.CalculatorActivity;
import com.lzb.browser.activity.CompassActivity;
import com.lzb.browser.activity.InputPatternPswActivity;
import com.lzb.browser.basic.utils.SPUtil;
import com.lzb.browser.basic.utils.StatusBarUtils;


public class SplashActivity extends AppCompatActivity {

    private static final long SPLASH_DELAY = 1500; // 1.5 秒

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_splash);
        StatusBarUtils.with(this).init();
        StatusBarUtils.setStatusBarTranslate(this);
        //设置状态栏字体颜色
        StatusBarUtils.setSystemStatusTextColor(false, this);

        int camouflage = SPUtil.getInt(getApplicationContext(), Content.camouflageMode, 0);
        if (camouflage == 0) {
            boolean isHave = SPUtil.getBoolean(getApplicationContext(), Content.isHavePassword, false);
            // 延时跳转
            new Handler(Looper.getMainLooper()).postDelayed(() -> {
                if (isHave) {
                    startActivity(new Intent(SplashActivity.this, InputPatternPswActivity.class));
                } else {
                    startActivity(new Intent(SplashActivity.this, HomeActivity.class));
                }
                finish(); // 防止返回键回到 Splash
            }, SPLASH_DELAY);
        } else if (camouflage == 1) {
            startActivity(new Intent(SplashActivity.this, CalculatorActivity.class));
            finish();
        } else if (camouflage == 2) {
            startActivity(new Intent(SplashActivity.this, CompassActivity.class));
            finish();
        }
    }
}